package org.dylan.bdf.system.dao;

import org.dylan.bdf.system.entity.User;
import org.dylan.common.dao.PagingDao;
import org.dylan.common.dao.hibernate.HibernatePagingDao;
import org.dylan.security.dao.IUserDao;
import org.dylan.security.entity.IUser;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

public interface UserDao extends UserDaoCustom, CrudRepository<User, String> {
	@Modifying
	@Query("update User set enabled=true where id=?1")
	public void enableUser(String userId);
	
	@Modifying
	@Query("update User set enabled=false where id=?1")
	public void disableUser(String userId);
	
	@Modifying
	@Query("update User set password=?2 where id=?1")
	public void changePassword(String id, String encryptPassword);
}

interface UserDaoCustom extends PagingDao<User, String>, IUserDao {

}

@Repository
class UserDaoImpl extends HibernatePagingDao<User, String> implements
		UserDaoCustom {

	@Override
	public IUser findByUsername(String username) {
		return findUniqueBy("username", username);
	}

}
